package quoridor;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;

public abstract class AbstractGame implements Game {
	Player playerWhite;
	Player playerBlack;
	
	Board gameBoard;
	
	//constructors taking references/parameters for the decision makers
	public AbstractGame (DecisionMakerType playerWhiteBrain, DecisionMakerType playerBlackBrain, String gameString) {
	    //make board with string
		gameBoard = new QuoridorBoard(gameString);
	}
	
	public AbstractGame (DecisionMakerType playerWhiteBrain, DecisionMakerType playerBlackBrain) {
	    //make empty board
		gameBoard = new QuoridorBoard();	
	}
	
	//private save function
	protected void saveGame() {
	  String savename = null;
	  try
      {
		 String gameString = gameBoard.getHistory();
		 Scanner in = new Scanner(System.in);

		 System.out.print("Please enter name of savegame desired:");
		 savename = in.next();
         FileWriter writeOut = new FileWriter(savename);
         BufferedWriter out = new BufferedWriter(writeOut);
         out.write(gameString);
         out.close();
      } catch (Exception e)
      {
         System.out.println("Couldn't write to file "+savename);
         e.printStackTrace();
         return;
      }
	}
	
	protected void exitGame() {
		//perform any operations required to exit the game
		QuoridorDisplay.instance().exitGameMessage();
	}
}
